package com.example.aics.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.model.embedding.EmbeddingModel;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.pinecone.PineconeEmbeddingStore;
import dev.langchain4j.store.embedding.pinecone.PineconeServerlessIndexConfig;
import jakarta.annotation.Resource;

@Configuration
public class PineconeConfig {

    @Value("${langchain4j.pinecone.api-key}")
    private String apiKey;

    @Value("${langchain4j.pinecone.index-name}")
    private String indexName;

    @Value("${langchain4j.pinecone.namespace}")
    private String namespace;

    @Value("${langchain4j.pinecone.cloud}")
    private String cloud ;

    @Value("${langchain4j.pinecone.region}")
    private String region;

    @Resource
    private EmbeddingModel embeddingModel;

    @Bean
    public EmbeddingStore<TextSegment>mbeddingStore() {
        return PineconeEmbeddingStore.builder()
                .apiKey(apiKey)  //  pincone 的api key
                .index(indexName) // 如果指定的索引不存在，那就创建该索引
                .nameSpace(namespace)  // 如果指定的命名空间不存在，那就创建该命名空间
                    .createIndex(PineconeServerlessIndexConfig.builder()
                    .cloud(cloud)  // 指定索引部署在哪个云服务器上
                    .region(region)  // 指定云服务器的区域
                    .dimension(embeddingModel.dimension())  // 向量维度
                    .build())
                .build();
    }
}
